Skip to content

feat(lk): lk agent builder manages Agent Builder agents under --user-auth - #1136

Merged
Topherhindman merged 28 commits into
mainfrom
topherhindman/devx-973-builder-commands
Dec 3, 2026
Merged

Topherhindman merged 28 commits into
mainfrom
topherhindman/devx-973-builder-commands

Conversation

@Topherhindman

@Topherhindman Topherhindman commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes DEVX-973

Why

The Public API serves Agent Builder agents (livekit/public-api-server#194, renamed in livekit/public-api-server#220), but lk had no commands for them, so a CLI user couldn't list, inspect, change, deploy, roll back or download one.

What changed

  • lk agent builder with list, get, create, update, deploy, delete, versions, download and update-secrets, under --user-auth, on the Public API's AgentBuilderService (/v0/projects/{project_id}/agent-builder/agents). The client is regenerated from livekit/public-api-server@372fb27e, which is production (v2026-12-02-2258), for UpdateAgentSecrets. It also drops the eval criterion type "code" and its check field (livekit/public-api-server#256), which lk doesn't use. Agent Builder agents are cloud-only, so the group has no API-key backend: it calls pkg/public directly, and is hidden until a user signs in, like lk project webhook.
  • AGENT_ID is the AB_ ID that list prints and the dashboard shows. The CA_ ID that the other lk agent commands take shows as Cloud Agent ID in the tables and cloudAgentId in --json.
  • Configurations are JSON files (--config-file FILE, or - for stdin), sent and printed verbatim. The generated config type drops properties the client's spec predates, so lk never decodes a configuration into it. A file holding a whole agent is refused, since the API would ignore its properties and reset the configuration. A syntax error names its line and column. list and versions refuse a --limit that doesn't fit an int32, as the other list commands do.
  • get --json and versions --json warn when header values read as ********, which create and update refuse.
  • deploy --version deploys an earlier version (the rollback). --wait follows the deployment until it is up (RUNNING, or SLEEPING when it scales to zero) or fails, for up to 15 minutes. It stops early when the agent is deleted (DELETING, or not found), or its deployment goes away after the build (NOT_DEPLOYED); UNSPECIFIED keeps it waiting. It reads the agent once before the deploy, so a failure is reported as one even when it never saw the build start, unless the agent had already failed or its status was unknown. A status left over from the previous deployment doesn't end the wait; that check compares server times only. Temporary read errors are retried, and when a timeout, an interrupt or read errors stop the wait early, lk says the deployment continues and how to follow it. --json prints the deploy's answer (versionId, status) with or without --wait; after the wait, status is the one it ended on.
  • download gets a 60-second signed URL and fetches the zip without the session token. Files are written 0600, an overwritten --output included, because the agent code holds header values in plaintext. --unzip DIR unpacks into an empty or new directory through os.Root, and stops at 256 MiB unpacked. If the unpack fails, it removes what it made and nothing else, so files that something else wrote to DIR meanwhile stay. No error prints the URL's signature.
  • update-secrets AGENT_ID sets secrets (--secrets KEY=VALUE, repeatable, taken whole even with a comma; --secrets-file) and removes them (--remove NAME), through AgentBuilderService.UpdateAgentSecrets (livekit/public-api-server#242). Other secrets keep their values. It makes no version and doesn't deploy, but the agent restarts. lk drops the LIVEKIT_ names, which LiveKit Cloud sets. There is no --secret-mount, because an Agent Builder agent reads only environment secrets, and no --overwrite, because the API only sets and removes.
  • --secrets (lk agent and lk agent builder) and --attribute (lk agent create and deploy, lk room, lk token, lk perf) keep a $ in a value instead of expanding it to nothing, and keep bytes that aren't UTF-8. A pair lk can't parse names its key, never its value. --secrets-file still reads its file as dotenv.
  • A permission refusal from an Agent Builder, webhook, user, workspace, key, member or invite command no longer suggests re-running without --user-auth: those groups have no API-key path.

Testing

  • Rebased on lk main 3832720 (chore(auth): prepare for migration to user-auth as default #1156). go test ./cmd/lk/... ./pkg/public/... passes on every commit, including seven new testscripts (agent-builder-*.txtar, cloud-only-refusals.txtar) and unit tests for the raw config round trip, the deploy wait (including temporary errors before a BUILD_FAILED), the unzip (including files another process writes to DIR) and the download. The script fake now records request bodies, and a script checks that stateTools, which the generated types lack, reaches the API on create and update.
  • Local: against a public-api-server built at 3a389094 (no database), list, get, versions, deploy, download and delete each reach their AgentBuilderService RPC on the new routes; the old /agents/builder route is a 404.
  • Staging, on the routes before livekit/public-api-server#220: ran every command against beta-api.staging.livekit.cloud in a test project: create, list, get, update (rename + config), versions, deploy --version --wait (BUILDING → STARTING → RUNNING in ~35 s), download --unzip and to a file, and delete. As a READ member, get --json shows ******** with the warning, and update, download and delete are refused without the API-key hint. Writing the masked config back as an admin fails with the field violation. Downloading over an existing 0644 file leaves it 0600. Staging and production now serve the new routes. Repeated at 090418f on the new routes, against deployed staging: create, list, get, update (rename + config), versions, deploy --version --wait of the earlier version (BUILDING → STARTING → RUNNING in ~45 s), download to a file, --version --output over an existing 0644 file (now 0600), --unzip (8 files, all 0600), and delete (get then says not found). As a READ member, get --json and versions --json show ******** with the warning; update and download are refused for agent:manage, and delete for agent:delete, without the API-key hint. Writing the masked config back as an admin fails with the config.httpTools[0].headers[0].value field violation. list and versions refuse a --limit over 2147483647 before any request.
  • Staging (PAS main), update-secrets on a test agent created and then deleted: two --secrets (one value with commas) and a --secrets-file set three secrets, lk agent secrets lists them without LIVEKIT_API_KEY, and no version is added. --remove of two leaves the third. --json prints {"agentId", "secretsUpdated": true}. WRITE and READ are refused for agent_secret:manage without the API-key hint. A bad name, and a set and remove of the same name, print the API's field violations. A CA_ ID is refused with the API's message.

Not in this PR

  • Agent names in place of IDs.
  • Showing the deployed version in list: the API sets it only on get.

@Topherhindman
Topherhindman requested review from a team and rektdeckard November 20, 2026 02:46
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Wraps the Public API's AgentBuilderService: list, get, create, update,
deploy, delete, list versions, and the code URL. Configurations travel
as raw JSON in both directions. The generated configuration type drops
properties that this client's spec predates, so a configuration read
through it and written back would lose them; reads decode the response
body with the config kept verbatim, and writes send the caller's JSON
through the WithBody variants.

HasHiddenHeaderValues finds the ******** that a caller without
agent:manage reads in place of each header value.
Adds `lk agent builder` with list, get, create, update, deploy, delete
and versions, on the Public API's AgentBuilderService. Builder agents
exist only on LiveKit Cloud, so the commands require --user-auth and
call pkg/public directly, with no API-key backend. Like the other
Public-API-only groups, the group is hidden until a user signs in.

- Configurations are JSON files (--config-file FILE, or - for stdin),
  sent as written. A file that holds a whole builder agent is refused:
  the API ignores unknown properties, so it would reset the
  configuration to its defaults.
- get --json and versions --json print each configuration verbatim, and
  warn when header values show as ********, which create and update
  refuse.
- deploy --wait reads the agent every 3 seconds until the new deployment
  runs or fails, for up to 15 minutes. A status read before the new
  deployment shows can be the previous one's, so RUNNING counts only
  after BUILDING or STARTING, or with a deployedAt after the deploy, and
  a failure only after BUILDING or STARTING.
- Lists print one page, with the command that reads the next. The list
  table has no deployed version column: ListAgents doesn't set
  deployment.versionId, only GetAgent does.
… URL

The builder agent code download needs the same client: no credentials,
no cookie jar, and timeouts. recordingClient becomes signedURLClient.
No behavior change.
download asks GetBuilderAgentCodeURL for a signed URL, valid for 60
seconds because lk uses it at once, then fetches the zip through the
signed-URL client, without the session token. It writes the zip to
--output, or to the name the server suggests, which must not exist
yet; --unzip DIR unpacks it into an empty or new directory instead.

The code holds every header value of the configuration in plaintext,
so lk writes files 0600 and directories 0700. Unpacking goes through
os.Root, so no entry lands outside DIR, and an entry that is neither a
file nor a directory is an error. As with recordings, no error prints
the URL's signature.
cloudAPIError answers a permission denial with "re-run without
`--user-auth`". Builder agents have no API-key path, so that advice
only leads to "only available under --user-auth". cloudOnlyAPIError
says the account lacks access and stops there; every other error reads
as cloudAPIError. The builder commands use it.
…ey path

These groups have no API-key implementation either, so they answer
through cloudOnlyAPIError too. Each change replaces one call.
A config file with a syntax error, such as a trailing comma, was
reported as "the configuration must be a JSON object", which hides the
real problem. A syntax error now prints its line, column and the
parser's message; valid JSON that isn't an object keeps the old
message.

The line and column come from lineAndColumn, which the eval commands
added for their --file.
…r time

- A deployment whose agent scales to zero before the wait reads it
  settles in SLEEPING, which never ended the wait: it ran 15 minutes
  and failed. A sleeping agent is deployed, and a dispatch starts it,
  so SLEEPING now ends the wait as RUNNING does, after the same
  freshness check, and lk says the agent sleeps until a dispatch.
- An up status without a BUILDING or STARTING before it counted as
  the new deployment when its deployedAt was after the local time of
  the deploy. A client clock behind the server's could take the
  previous deployment for the new one. The reference is now the deploy
  response's Date header plus a second, since the header is truncated
  to the second: both times are server times. Without a Date header,
  only a BUILDING or STARTING lets the wait end.

DeployBuilderAgent returns the Date beside the API's answer, which
--json prints unchanged.
- Ctrl-C said "stopped waiting after 15m0s", as the timeout does. A
  cancel now says "stopped waiting", and only the timeout names its
  duration.
- One failed status read ended the wait, without saying that the
  deployment goes on. A network error, a 429 or a 5xx is now retried
  up to 3 times in a row, waiting twice as long before each try.
- Every early end, whether a cancel, the timeout or an error that
  stops the wait, ends with how to follow the deployment:
  lk agent builder get ID.
OpenFile applies its mode only to a file it creates, so a zip written
over an existing 0644 file stayed 0644, though the agent code holds
header values in plaintext. writePrivateFile now sets 0600 on the open
file before it writes, for a new and a replaced file alike.
An entry that failed partway through an unpack left the files before
it in DIR, so a second try was refused because DIR wasn't empty. On an
error, lk now removes DIR when the unpack created it, and otherwise
empties it again, since --unzip only takes an empty directory.
The script tests sent a config with an unknown property, but the fake
logged no bodies, so nothing showed it reached the wire. The fake now
keeps each request's body, and `body METHOD URL` prints the last one.
agent-builder-with-user-auth.txtar checks that stateTools, which the
generated types don't have, is in the create and the update body.
livekit/public-api-server#220 calls the AgentBuilderService resource an
"Agent Builder agent", and names its cloud agent ID (CA_)
`cloudAgentId`. lk's names and output follow it. The routes and the
generated client are unchanged.

- pkg/public: builder_agents.go is agent_builder.go. Its types and
  methods say AgentBuilderAgent.
- pkg/public/render: the tables' Agent ID column is Cloud Agent ID.
- cmd/lk: the argument is AGENT_ID, and the group's help says it is the
  AB_ ID, not the CA_ ID other lk agent commands take. Messages say
  "Agent Builder agent". delete --json prints {"agentId": ..., "deleted":
  true}.
download checks that the --unzip directory is empty before it fetches
the zip, which takes a while. Anything written to the directory in that
time was deleted when the unpack then failed: the cleanup emptied the
whole directory. An unpack that collided with such a file failed and
deleted it too.

The unpack now records each file and directory it makes, and its undo
removes those alone, newest first, each a directory only while empty.
Parents of the directory that it made go the same way. Entry paths that
aren't local are refused before os.Root sees them.
A failure ended the wait only after a BUILDING or STARTING read, so a
deployment that failed while status reads were failing, or before the
first read, ran to the 15-minute timeout and was reported as one.

deploy --wait now reads the agent before it deploys. When that read
doesn't show a failure, a failure read later is this deployment's, and
ends the wait as one. When the agent had already failed, or couldn't be
read, a failure without a BUILDING or STARTING may still be the old
one: the API has no deployment ID or build time that tells them apart,
so the wait still needs to see the build start.
A missing config file printed the OS error, "open missing.json: no such
file or directory" on macOS and Linux and "The system cannot find the
file specified." on Windows, so agent-builder-refusals.txtar failed on
Windows. lk now says "--config-file missing.json: the file doesn't
exist", like its other --config-file errors, and prefixes any other
read error with the flag and path.
…a failure

The API leaves an agent's deployment out when it can't read the status.
deploy --wait took that baseline as "not failed", so a failure read
after the deploy, which could still be the previous deployment's,
ended the wait as this deployment's failure. An unknown status, like an
unreadable agent, now counts as possibly failed, so such a failure ends
the wait only after a BUILDING or STARTING.
int32(cmd.Int("limit")) wrapped a --limit over 2147483647 to another
page size, such as 4294967346 to 50. Both commands now read it with
int32Flag, as the other list commands do since #1146, and refuse it
before any request.
#1156 resolves a user-auth command's project from --subdomain, LIVEKIT_URL
and livekit.toml as well as --project, and makes user auth the default in
3.0. The other Public-API commands' usage lines, such as lk agent eval's,
name neither flag; the group's "(requires --user-auth)" stays, as theirs
does.
@Topherhindman
Topherhindman force-pushed the topherhindman/devx-973-builder-commands branch from 090418f to a81489a Compare December 2, 2026 23:00
devin-ai-integration[bot]

This comment was marked as resolved.

Picks up AgentBuilderService.UpdateAgentSecrets, which
livekit/public-api-server#242 added. It also drops the eval criterion
type "code" and its `check` field (livekit/public-api-server#256),
which lk doesn't use. No hand-written code changes.

Generated from livekit/public-api-server@372fb27, which is production (v2026-12-02-2258)
… secrets

Wraps AgentBuilderService.UpdateAgentSecrets, which
livekit/public-api-server#242 added. The secrets that the command doesn't
name keep their values. The update makes no version and doesn't deploy,
but the agent restarts to read them. The API asks agent_secret:manage.

- Secrets come as lk agent update-secrets takes them: --secrets KEY=VALUE,
  repeatable and taken whole when the value has a comma, and
  --secrets-file. lk drops the LIVEKIT_ names, which LiveKit Cloud sets.
  There is no --secret-mount: an Agent Builder agent reads only
  environment secrets, and the API refuses a file secret.
- --remove NAME removes a secret. There is no --overwrite: the API only
  sets and removes.
- lk sends the secrets sorted by name, and refuses a run with nothing to
  set or remove before any request.
parseKeyValuePairs reads --secrets for lk agent create, deploy, update,
update-secrets and lk agent builder update-secrets, and --attribute for
lk agent create and deploy, lk room, lk token and lk perf. It put the
whole pair in its error, and godotenv's error, which quotes the pair
again. For --secrets that printed the secret. The error now names the
flag, the pair's position and its key, which is the text before the
first =.
…ritten

parseKeyValuePairs parses each KEY=VALUE pair with godotenv, which
expands $NAME and ${NAME} from the variables parsed before them. A pair
has none, so the expansion could only erase: --secrets
'DB_PASSWORD=rotated$SUFFIX' stored "rotated". Each pair is now parsed
with its unescaped $ signs hidden. Quotes, an escaped \$, comments and
export still read as before, and --secrets-file, a real dotenv file,
still expands.

agent-builder-update-secrets.txtar checks that the API gets the value
whole, and that a pair lk can't parse names its key but not its value.

@rektdeckard rektdeckard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments, nonblocking but worth fixing. The different message shape with and without --wait is the one weird thing to me.

Comment thread cmd/lk/agent_builder.go Resolved
Comment thread cmd/lk/user_auth.go Resolved
Comment thread cmd/lk/agent_builder.go Resolved
Comment thread cmd/lk/agent_builder.go Resolved
@Topherhindman
Topherhindman force-pushed the topherhindman/devx-973-builder-commands branch from 21b8e91 to 2ceaa2c Compare December 2, 2026 23:37
devin-ai-integration[bot]

This comment was marked as resolved.

… --wait

deploy --json printed the deploy's answer, {"versionId", "status"}, but
deploy --wait --json printed the whole agent, so a script had to know
which flags it ran with. Both now print the deploy's answer. After
--wait its status is the one the wait ended on, RUNNING or SLEEPING, as
lk sip's --wait keeps the answer's shape. Without --json, --wait still
prints the agent's table.
The download reads at most 100 MiB of zip, but a zip can unpack to far
more than its size, and --unzip copied each entry without a bound. It
now copies through a LimitReader, and stops when the files together
pass maxUnpackedAgentCode (256 MiB). The error says so, and the unpack
removes what it wrote, as on any other error.
A wait read DELETING, NOT_DEPLOYED and UNSPECIFIED as "not up yet", so
deleting the agent during deploy --wait polled for 15 minutes and ended
on the timeout, and a deleted agent's 404 ended it with "the deployment
continues". Now:

- DELETING ends the wait: the agent is being deleted.
- NOT_DEPLOYED ends it after a BUILDING or STARTING: the deployment went
  away. Before the build shows, it can be the state before the build,
  so the wait goes on.
- A 404 ends it without the "deployment continues" hint: the deploy
  found the agent, so it was deleted since.
- UNSPECIFIED, or a status lk doesn't know, keeps the wait going: it may
  pass, and the timeout bounds it.
2ceaa2c hid each $ by ranging over the pair as runes and writing each
rune back, which turned a byte that isn't UTF-8 into U+FFFD, so a quoted
--secrets value with a $ and such a byte reached the API changed.
godotenv does the same to an unquoted value on its own, with or without
a $, as it reads one as runes.

hideFromDotenv now walks the pair by byte, and hides a byte that isn't
UTF-8 behind a private-use rune too, as it hides a $. The runes are ones
the pair doesn't hold, and restore turns each back into its byte. A test
covers single-quoted, double-quoted and unquoted values with a $ and
such bytes, and valid UTF-8, U+FFFD and private-use runes, which pass
unchanged.
lk project key, member and invite run only under --user-auth, as
webhooks, users and workspaces do, but a refusal for the user's role
still told them to re-run without --user-auth, where the commands don't
exist. They use cloudOnlyAPIError now, as dee252f's groups do.
@Topherhindman
Topherhindman merged commit 140640a into main Dec 3, 2026
27 checks passed
@Topherhindman
Topherhindman deleted the topherhindman/devx-973-builder-commands branch December 3, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants